//
//  HJSwitchTitleSubTitleCell.m
//  KaiChat
//
//  Created by lx on 2024/1/18.
//

#import "HJSwitchTitleSubTitleCell.h"
#import "HJSwichView.h"
 
@interface HJSwitchTitleSubTitleCell()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *subTitleLabel;
@property (nonatomic, weak) HJSwichView *switchView;
@property (nonatomic, weak) UIView *lineView;

@end

@implementation HJSwitchTitleSubTitleCell


- (void)settingSubView {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _titleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.top.offset(15);
    }];
    
    _subTitleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    _subTitleLabel.numberOfLines = 0;
    [_subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.top.equalTo(_titleLabel.mas_bottom).offset(6);
        make.right.inset(72);
    }];
    
    _switchView = [HJSwichView addToView:self.contentView];
    _switchView.onTintColor = UIColor.tj_mainColor;
    [_switchView addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
    _switchView.transform = CGAffineTransformMakeScale(0.85, 0.85);
    [_switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.centerY.offset(0);
    }];

    
    _lineView = [UIView addToView:self.contentView];
    _lineView.backgroundColor = [UIColor.tj_CCCCCCColor colorWithAlphaComponent:0.2];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.bottom.offset(0);
        make.height.offset(lineHeight);
    }];
    
}

- (void)switchValueChanged:(HJSwichView *)switchView {
    if (_switchValueChange) {
        _switchValueChange(switchView);
    }
}


- (void)setModel:(HJCellModel *)model {
    _model = model;
    
    _titleLabel.text = model.text;
    _subTitleLabel.text = model.subText;
        
    _switchView.on = model.isOn;
    _lineView.hidden = !model.showLine;

    [_lineView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.inset(model.separatorInset.left);
        make.right.inset(model.separatorInset.right);
    }];
}

@end
